package com.devbobcorn.nekoration.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;

import java.util.Map;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;

import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.state.StateManager;

public abstract class DyeableHorizontalBlock extends DyeableBlock {
    public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;

    protected DyeableHorizontalBlock(Settings settings) {
        super(settings);
    }

    protected void appendProperties(StateManager.Builder<Block, BlockState> s) {
        s.add(COLOR, FACING);
    }

    public BlockState getPlacementState(ItemPlacementContext ctx) {
        return super.getPlacementState(ctx).with(FACING, ctx.getPlayerFacing().getOpposite());
    }

    protected static Map<Direction, VoxelShape> getAABBs(double thickness){
        return Maps.newEnumMap(ImmutableMap.of(
                Direction.NORTH, Block.createCuboidShape(0.0D, 0.0D, 16.0D - thickness, 16.0D, 16.0D, 16.0D),
                Direction.SOUTH, Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, thickness), 
                Direction.EAST, Block.createCuboidShape(0.0D, 0.0D, 0.0D, thickness, 16.0D, 16.0D),
                Direction.WEST, Block.createCuboidShape(16.0D - thickness, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)));
    }

    public BlockPos getLeftBlock(BlockPos pos, Direction dir) {
        switch (dir) {
        case NORTH:
            return pos.east();
        case EAST:
            return pos.south();
        case SOUTH:
            return pos.west();
        default:
            return pos.north();
        }
    }
    
    public BlockPos getRightBlock(BlockPos pos, Direction dir) {
        switch (dir) {
        case NORTH:
            return pos.west();
        case EAST:
            return pos.north();
        case SOUTH:
            return pos.east();
        default:
            return pos.south();
        }
    }

    public Direction getLeftDir(Direction selfDir) {
        switch (selfDir) {
        case NORTH:
            return Direction.EAST;
        case EAST:
            return Direction.SOUTH;
        case SOUTH:
            return Direction.WEST;
        default:
            return Direction.NORTH;
        }
    }
    
    public Direction getRightDir(Direction selfDir) {
        switch (selfDir) {
        case NORTH:
            return Direction.WEST;
        case EAST:
            return Direction.NORTH;
        case SOUTH:
            return Direction.EAST;
        default:
            return Direction.SOUTH;
        }
    }
}